<?php
/**
 * Created by PhpStorm.
 * User: lelouchms
 * Date: 2019/3/28
 * Time: 16:08
 */

namespace app\backend\controller\admin\v1;

use app\backend\controller\BackendController;
use app\common\exception\CustomerException;
use app\common\exception\ValidateException;

class HouseType extends Base
{

    public function initialize()
    {
        parent::initialize();
        $this->model = new \app\common\model\HouseType();
    }

    public function add()
    {
        $requestData = $this->request->post();
        $validate = new \app\common\validate\HouseType();
        $flag = $validate->scene("add")->check($requestData);
        if ($flag === false) {
            throw new ValidateException($validate->getError());
        }
        $insertId = $this->model->insert($requestData, false, true);
        if (empty($insertId)) throw new CustomerException("新增失败");
    }

    public function update()
    {
        $requestData = $this->request->post();
        $validate = new \app\common\validate\HouseType();
        $flag = $validate->scene("update")->check($requestData);
        if ($flag === false) {
            throw new ValidateException($validate->getError());
        }
        $count = $this->model->where("id", $requestData["id"])->update($requestData);
        if ($count > 1) throw new CustomerException("编辑失败");
        $this->_removeCache($requestData);
    }


}